/* 
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2010. All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:  Use,
 * duplication or disclosure restricted by GSA ADP Schedule
 * Contract with IBM Corp.
 *
 * This code is released under the terms of the Eclipse Public License
 * version 1.0 which can be found at the top level of this project or
 * or at http://www.eclipse.org/org/documents/epl-v10.php
 */

package com.ibm.mining;

public class Pair<T, U> {
	   public final T first;
	   public final U second;


	   private Pair(T first, U second) {
	       if (first == null || second == null)
	           throw new NullPointerException();

	       this.first = first;
	       this.second = second;
	   }

	   public static <T, U> Pair<T, U> of(T first, U second) {
	       if (first == null || second == null)
	           throw new NullPointerException();
	       return new Pair<T, U>(first, second);
	   }

	   public String toString() {
		   	return "Pair<" + first.getClass().getSimpleName() + ", " + 
		   		second.getClass().getSimpleName() + ">(" 
		   		+ first + ", " + second + ")";
	   }

	   public boolean equals(Object o) {
	       if (this == o) return true;
	       if (o == null || getClass() != o.getClass()) return false;

	       Pair pair = (Pair) o;

	       return first.equals(pair.first) && second.equals(pair.second);
	   }

	   public int hashCode() {
	       int result;
	       result = first.hashCode();
	       result = 31 * result + second.hashCode();
	       return result;
	   }
	}